/**
  * AntRanking Copyright (c) 2008-2012 INRIA, University of Lille 1
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * Contact: 
  * 	benjamin.bertein@gmail.com,
  * 	nacim.hamdad@gmail.com
  * 	nicolas.haderer@inria.fr
  *
  * Author: Nacim Hamdad,Benjamin Bertein, Haderer Nicolas
  */
package com.google.antranking;

import com.google.antranking.activity.RankingActivity;
import com.google.antranking.activity.RankingActivityTab;
import com.google.antranking.activity.SettingActivity;
import com.google.antranking.adapter.AntRankingGridAdapter;
import com.google.antranking.utils.AtConfiguration;
import com.google.antranking.utils.AtConstant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;


public class AntRankingActivity extends Activity implements OnItemClickListener{

	final public static String MENU_SETTING = "Setting";
	final public static String PRIVACY_STRING = "Ranking";
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

		setContentView(R.layout.main);

		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.header);

		AtConfiguration.initializeConfigurationFile(getBaseContext());

		((TextView)this.findViewById(R.id.main_title)).setText(
				AtConfiguration.getStringValue(this,AtConstant.PREF_USERNAME,""));
		
	}

	@Override
	public void onStart(){
		super.onStart();
		
		final GridView gridview = (GridView) findViewById(R.id.gridView);
		gridview.setAdapter(
				new AntRankingGridAdapter(
						this,
						new Integer[]{
								R.drawable.ic_setting,
								R.drawable.ic_privacy,
						},
						new String[]{
							MENU_SETTING,
							PRIVACY_STRING,
					}));

		gridview.setOnItemClickListener(this);			
	}
	
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		
		if (view.getTag().equals(MENU_SETTING)){
			final Intent intent = new Intent(getBaseContext(),SettingActivity.class);
			startActivity(intent);
		}
		else if(view.getTag().equals(PRIVACY_STRING)){
			try{
				final Intent intent = new Intent(getBaseContext(),RankingActivityTab.class);
				startActivity(intent);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			
		}
	}
}